package com.songtai.action.front;

import java.util.ArrayList;
import java.util.List;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.News;
import com.songtai.po.PhotoObj;
import com.songtai.po.PublicObj;
import com.songtai.service.ImageService;
import com.songtai.service.NewsService;
import com.songtai.service.PublicObjService;
import com.songtai.util.StringUtil;

/**
 * @author 赵中杨
 * @email zhaozhongyang717@gmail.com
 * @date 2010 2010-4-21 下午03:34:04
 */
public class HomeAction extends SongtaiActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5103285100848303314L;
	private NewsService newsService;
	private ImageService imageService;
	// 新闻动态
	private List<News> dnews;
	// 装修知识
	private List<News> znews;
	// 公司简介字符串
	private String intro;
	// 新闻动态节点ID
	private Long dnewsid = 13L;
	// 装修知识节点ID
	private Long znewsid = 11L;
	// 公司简介节点ID
	private Long introid = 6L;
	// 家装案例节点ID
	private Long jiaid = 15L;
	// 工装案例节点ID
	private Long gongid = 16L;
	// 图片幻灯片ID
	private Long slider_id = 2L;
	private List<PhotoObj> jiaList;

	private List<PhotoObj> gongList;

	private List<PhotoObj> sliderList;

	private PublicObjService publicObjService;
	private PublicObj pub;
	private List<PublicObj> qq;

	/**
	 * 首页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String home() throws Exception {
		// 获取新闻动态
		dnews = cutString(newsService.getRecentNews(5, dnewsid));
		// 读取装修知识
		znews = cutString(newsService.getRecentNews(5, znewsid));
		// 读取公司简介
		List<PhotoObj> list = imageService.getImageByNodeid(introid, 1,
				PhotoObj.TYPE_COMPANY_INTROUCE);
		if (list != null && !list.isEmpty()) {
			PhotoObj obj = list.get(0);
			intro = StringUtil.abbreviate(StringUtil.Html2Text(obj
					.getElseContent()), 600, "...");
		}
		// 读取家装案例
		jiaList = imageService.getRecentImage(20, PhotoObj.TYPE_CASE, jiaid);
		//getImageByNodeid(jiaid, 20, PhotoObj.TYPE_CASE);
		// 读取工装案例
		gongList = imageService.getRecentImage(20, PhotoObj.TYPE_CASE, gongid);
			//	.getImageByNodeid(gongid, 20, PhotoObj.TYPE_CASE);
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10,
				PhotoObj.TYPE_SLIDER);

		pub = publicObjService.getObjByNid("21");

		qq = publicObjService.getObjsByNid("23");
		return SUCCESS;
	}

	public List<PublicObj> getQq() {
		return qq;
	}

	public void setQq(List<PublicObj> qq) {
		this.qq = qq;
	}

	/**
	 * @return the newsService
	 */
	public NewsService getNewsService() {
		return newsService;
	}

	/**
	 * @param newsService
	 *            the newsService to set
	 */
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}

	/**
	 * @return the imageService
	 */
	public ImageService getImageService() {
		return imageService;
	}

	/**
	 * @param imageService
	 *            the imageService to set
	 */
	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	/**
	 * @return the dnews
	 */
	public List<News> getDnews() {
		return dnews;
	}

	/**
	 * @param dnews
	 *            the dnews to set
	 */
	public void setDnews(List<News> dnews) {
		this.dnews = dnews;
	}

	/**
	 * @return the znews
	 */
	public List<News> getZnews() {
		return znews;
	}

	/**
	 * @param znews
	 *            the znews to set
	 */
	public void setZnews(List<News> znews) {
		this.znews = znews;
	}

	/**
	 * @return the intro
	 */
	public String getIntro() {
		return intro;
	}

	/**
	 * @param intro
	 *            the intro to set
	 */
	public void setIntro(String intro) {
		this.intro = intro;
	}

	/**
	 * @return the jiaList
	 */
	public List<PhotoObj> getJiaList() {
		return jiaList;
	}

	/**
	 * @param jiaList
	 *            the jiaList to set
	 */
	public void setJiaList(List<PhotoObj> jiaList) {
		this.jiaList = jiaList;
	}

	/**
	 * @return the gongList
	 */
	public List<PhotoObj> getGongList() {
		return gongList;
	}

	/**
	 * @param gongList
	 *            the gongList to set
	 */
	public void setGongList(List<PhotoObj> gongList) {
		this.gongList = gongList;
	}

	/**
	 * @return the sliderList
	 */
	public List<PhotoObj> getSliderList() {
		return sliderList;
	}

	/**
	 * @param sliderList
	 *            the sliderList to set
	 */
	public void setSliderList(List<PhotoObj> sliderList) {
		this.sliderList = sliderList;
	}

	/**
	 * @return the publicObjService
	 */
	public PublicObjService getPublicObjService() {
		return publicObjService;
	}

	/**
	 * @param publicObjService
	 *            the publicObjService to set
	 */
	public void setPublicObjService(PublicObjService publicObjService) {
		this.publicObjService = publicObjService;
	}

	/**
	 * @return the pub
	 */
	public PublicObj getPub() {
		return pub;
	}

	/**
	 * @param pub
	 *            the pub to set
	 */
	public void setPub(PublicObj pub) {
		this.pub = pub;
	}

	private List<News> cutString(List<News> list) {
		List<News> new_list = new ArrayList<News>();
		if (list != null && !list.isEmpty()) {
			for (News news : list) {
				News new_news = new News();
				new_news.setTitle(StringUtil.abbreviate(news.getTitle(), 30,
						"..."));
				new_news.setContent(news.getContent());
				new_news.setNid(news.getNid());
				new_news.setRecordTime(news.getRecordTime());
				new_news.setId(news.getId());
				new_list.add(new_news);
			}
		}
		return new_list;
	}
}
